home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Applications / Flight Stability / Flight Stability Source / CFSStickPane.p < prev    next >
Encoding:
Text File  |  1995-07-03  |  3.2 KB  |  144 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CFSStickPane.p                                                                                                                                                                                                }
  4. {}
  5. {        Pane methods for the joystick pane.                                                                                                                                    }
  6. {}
  7. {        Copyright © 1995, Patrick Hew.  All rights reserved.                                                                            }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CFSStickPane;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, FSIntf;
  18.  
  19. implementation
  20.  
  21.  
  22. { IFSStickPane }
  23. {}
  24. { Post: The stick pane has been initialized. }
  25.  
  26.     procedure CFSStickPane.IFSStickPane (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption);
  27.  
  28.     begin { IFSStickPane }
  29.         IPane(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
  30.  
  31.         stickh := 0;
  32.         stickv := 0;
  33.  
  34.         { oldMousePt is initialized in the DoCommand method. }
  35.  
  36.     end; { IFSStickPane }
  37.  
  38.  
  39. { Draw }
  40. {}
  41. { Post: The stick pane has been drawn. }
  42.  
  43.     procedure CFSStickPane.Draw (var area: Rect);
  44.  
  45.     begin { Draw }
  46.         MoveTo(kStickHalfWidth, kStickHalfHeight);
  47.         Line(stickh, stickv);
  48.     end; { Draw }
  49.  
  50.  
  51. { InitOldMousePt }
  52. {}
  53. { Pre: The game director has received the command to take control. }
  54. { Post: The old mouse position has been initialized, ready for control }
  55. {   measurement on the next event loop. }
  56.  
  57.     procedure CFSStickPane.InitOldMousePt;
  58.  
  59.         var
  60.             theMousePt: Point;
  61.  
  62.     begin     { InitOldMousePt }
  63.         { Remember - Never pass an instance variable }
  64.         { by reference. }
  65.         Prepare;
  66.         GetMouse(theMousePt);
  67.         oldMousePt := theMousePt;
  68.     end; { InitOldMousePt }
  69.  
  70.  
  71. { GetControl }
  72. {}
  73. { Post: aBankChange and aAOAChange are respectively the change in }
  74. {        bank and AOA, based on the offset of the mouse from the centre }
  75. {        of the stick pane. }
  76.  
  77.     procedure CFSStickPane.GetControl (var aBankChange, aAOAChange: Real);
  78.  
  79.         var
  80.             currMousePt: Point;
  81.             offseth, offsetv: Integer;
  82.             oldstickh: StickHorRange;
  83.             oldstickv: StickVerRange;
  84.  
  85.     begin { GetControl }
  86.         oldstickh := stickh;
  87.         oldstickv := stickv;
  88.  
  89.         { Take coordinates relative to the current GrafPort. }
  90.  
  91.         Prepare;
  92.         GetMouse(currMousePt);
  93.  
  94.         offseth := currMousePt.h - oldMousePt.h;
  95.         offsetv := currMousePt.v - oldMousePt.v;
  96.  
  97.         oldMousePt := currMousePt;
  98.  
  99.         { Correct for overlarge changes in mouse position. }
  100.  
  101.         if offseth < -kStickHalfWidth then begin
  102.             stickh := -kStickHalfWidth;
  103.         end { if }
  104.         else if offseth > kStickHalfWidth then begin
  105.             stickh := kStickHalfWidth;
  106.         end { else if }
  107.         else begin
  108.             stickh := StickHorRange(offseth);
  109.         end; { else }
  110.  
  111.         if offsetv < -kStickHalfHeight then begin
  112.             stickv := -kStickHalfHeight;
  113.         end { if }
  114.         else if offsetv > kStickHalfHeight then begin
  115.             stickv := kStickHalfHeight;
  116.         end { else if }
  117.         else begin
  118.             stickv := StickVerRange(offsetv);
  119.         end; { else }
  120.  
  121.         if (oldstickh <> stickh) or (oldstickv <> stickv) then begin
  122.             Refresh;
  123.         end; { else }
  124.  
  125.         aBankChange := pi * stickh / (kStickHalfWidth * 12);    { 15° bank change per frame. }
  126.         aAOAChange := pi * stickv / (kStickHalfHeight * 12); { 15° AOA change per frame. }
  127.  
  128.     end; { GetControl }
  129.  
  130.  
  131. { CentreStick }
  132. {}
  133. { Post: The stick has been centred and refreshed. }
  134.  
  135.     procedure CFSStickPane.CentreStick;
  136.  
  137.     begin { CentreStick }
  138.         stickh := 0;
  139.         stickv := 0;
  140.         Refresh;
  141.     end; { CentreStick }
  142.  
  143.  
  144. end. { CFSStickPane }